from odoo import api, fields, models


class factory(models.Model):
    _name = 'factory'
    _description = 'factory'
    name = fields.Char('厂家法定名称', required=True)
    factory_id = fields.Char(
        string='工厂编号',
        index=True,
        readonly=True,
        default='自动生成'
    )
    fac_scale = fields.Selection([
        ('0', '小型'),
        ('1', '中小型'),
        ('2', '中型'),
        ('3', '大型')
    ], required=True, string='工厂规模')
    address = fields.Char('厂家地址', requierd=True)
    product = fields.Selection([
        ('0', 'HPV疫苗'),
        ('1', '狂犬病疫苗'),
        ('2', '卡介苗'),
        ('3', '其他')
    ], requierd=True, string='厂家主要产品情况')
    fax = fields.Char('厂家传真', requierd=True)
    admin = fields.Many2one('res.users', string='联系人', requierd=True)
    tel = fields.Char(related='admin.mobile', string='联系人电话', requierd=True)
    organization = fields.Selection([
        ('0', '分公司')
        , ('1', '子公司'),
        ('2', '部门'),
        ('3', '经销点'),
        ('4', '代理商')
    ], requierd=True, string='机构性质')

    busniess_scope = fields.Selection([
        ('0', '疫苗'),
        ('1', '药品'),
        ('2', '其他')

    ], requierd=True, string='经营范围')

    fund = fields.Char('注册资金', requierd=True)
    image = fields.Binary('营业许可证', requierd=True)
    date = fields.Date('工厂成立日期', required=True)

    @api.model
    def create(self, vals):
        vals['factory_id'] = self.env['ir.sequence'].next_by_code('factory') or ''
        return super(factory, self).create(vals)
